package cn.com.thingo.hyintelligent.ui.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.thingo.hyintelligent.R;
import cn.com.thingo.hyintelligent.model.bean.GatewayListBean;

public class GatewayListViewAdapter extends BaseAdapter {
    private List<GatewayListBean.DataBean> gatewayList;
    private Context context;

    public GatewayListViewAdapter(List<GatewayListBean.DataBean> gatewayList, Context context) {
        this.gatewayList = gatewayList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return gatewayList.size();
    }

    @Override
    public Object getItem(int position) {
        return gatewayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        GatewayViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_gateway_list, parent, false);
            viewHolder = new GatewayViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (GatewayViewHolder) convertView.getTag();
        }
        viewHolder.tvName.setText(gatewayList.get(position).getTitle());
        viewHolder.tvNum.setText(gatewayList.get(position).getNumber());
        return convertView;
    }


    public static class GatewayViewHolder extends BaseViewHolder {
        @BindView(R.id.gateway_list_name)
        TextView tvName;
        @BindView(R.id.gateway_list_num)
        TextView tvNum;
        @BindView(R.id.gateway_list_select)
        ImageView tvSelect;
        @BindView(R.id.item_view_gateway_list)
        View itemView;

        private GatewayViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
